﻿#region Header

// <file>
//     <copyright see="prj:///doc/copyright.txt"/>
//     <license see="prj:///doc/license.txt"/>
//     <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
//     <version>$Revision: 1965 $</version>
// </file>

#endregion Header

namespace ICSharpCode.TextEditor.Gui.CompletionWindow
{
    using System;
    using System.Drawing;
    using System.Windows.Forms;

    using ICSharpCode.TextEditor.Util;

    public interface IDeclarationViewWindow
    {
        #region Properties

        string Description
        {
            get;
            set;
        }

        #endregion Properties

        #region Methods

        void CloseDeclarationViewWindow();

        void ShowDeclarationViewWindow();

        #endregion Methods
    }

    public class DeclarationViewWindow : Form, IDeclarationViewWindow
    {
        #region Fields

        public bool HideOnClick;

        string description = String.Empty;

        #endregion Fields

        #region Constructors

        public DeclarationViewWindow(Form parent)
        {
            SetStyle(ControlStyles.Selectable, false);
            StartPosition   = FormStartPosition.Manual;
            FormBorderStyle = FormBorderStyle.None;
            Owner           = parent;
            ShowInTaskbar   = false;
            Size            = new Size(0, 0);
            base.CreateHandle();
        }

        #endregion Constructors

        #region Properties

        public string Description
        {
            get {
                return description;
            }
            set {
                description = value;
                if (value == null && Visible) {
                    Visible = false;
                } else if (value != null) {
                    if (!Visible) ShowDeclarationViewWindow();
                    Refresh();
                }
            }
        }

        protected override CreateParams CreateParams
        {
            get {
                CreateParams p = base.CreateParams;
                AbstractCompletionWindow.AddShadowToWindow(p);
                return p;
            }
        }

        protected override bool ShowWithoutActivation
        {
            get {
                return true;
            }
        }

        #endregion Properties

        #region Methods

        public void CloseDeclarationViewWindow()
        {
            Close();
            Dispose();
        }

        public void ShowDeclarationViewWindow()
        {
            Show();
        }

        protected override void OnClick(EventArgs e)
        {
            base.OnClick(e);
            if (HideOnClick) Hide();
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            if (description != null && description.Length > 0) {
                TipPainterTools.DrawHelpTipFromCombinedDescription(this, pe.Graphics, Font, null, description);
            }
        }

        protected override void OnPaintBackground(PaintEventArgs pe)
        {
            pe.Graphics.FillRectangle(SystemBrushes.Info, pe.ClipRectangle);
        }

        #endregion Methods
    }
}